package com.alibaba.algo.dao.user;

import com.alibaba.algo.cooperation.feign.vo.req.SelectGroupPageRequestVO;
import com.alibaba.algo.cooperation.usercomponent.vo.res.user.EmployeeGroupInfoVO;
import com.alibaba.algo.cooperation.usercomponent.vo.res.user.EmployeeInfo;
import com.alibaba.algo.core.base.BaseMapper;
import com.alibaba.algo.entity.user.SysEmployeeGroup;
import com.alibaba.algo.entity.user.SysGroup;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 类SysEmployeeGroupMapper.java的实现描述：用户组关系表Mapper
 *
 * @author fan.tianpeng 2021-05-06 20:30:48
 */
public interface SysEmployeeGroupMapper extends BaseMapper<SysEmployeeGroup> {

    void batchInsert(@Param("sysEmployeeGroupList") List<SysEmployeeGroup> sysEmployeeGroupList);

    /**
     * 查询全量的用户组员工
     *
     * @param groupId 用户组标识
     * @return 员工列表
     */
    List<EmployeeInfo> selectEmployeeListByGroupCondition(
            @Param("groupId") Long groupId,
            @Param("employeeName") String employeeName,
            @Param("userAccount") String userAccount,
            @Param("employeeCode") String employeeCode,
            @Param("employeeId") Long employeeId,
            @Param("userName") String userName,
            @Param("userId") Long userId,
            @Param("searchKey") String searchKey);

    List<EmployeeInfo> pageEmployeeByGroupId(@Param("groupId") Long groupId, @Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize);

    Integer pageEmployeeCountByGroupId(@Param("groupId") Long groupId);

    Integer countEmployeeListByGroupCondition(@Param("groupId") Long groupId);

    List<EmployeeInfo> selectListWithGroupIdByGroupCondition(
            @Param("groupId") Long groupId,
            @Param("employeeName") String employeeName,
            @Param("userAccount") String userAccount,
            @Param("employeeCode") String employeeCode,
            @Param("employeeId") Long employeeId,
            @Param("userName") String userName,
            @Param("userId") Long userId,
            @Param("searchKey") String searchKey);

    /**
     * 查询员工所在的用户组
     *
     * @param employeeId 员工标识
     * @return 用户组列表
     */
    List<SysGroup> selectGroupListByEmployeeId(@Param("employeeId") Long employeeId);

    SysEmployeeGroup selectOneByEmployeeIdAndGroupId(@Param("employeeId") Long employeeId, @Param("groupId") Long groupId);

    /**
     * 查询用户组下的员工列表
     *
     * @param groupId 用户组标识
     * @return 员工列表
     */
    List<EmployeeGroupInfoVO> selectList(@Param("groupId") Long groupId);

    /**
     * 根据用户组id删除
     *
     * @param groupId
     */
    void deleteByGroupId(@Param("groupId") Long groupId);


    /**
     * 查询直接和人员组关联的人员个数
     *
     * @param groupId
     * @return
     */
    Integer countDirectEmployeeNumByGroupCondition(@Param("groupId") Long groupId);

    /**
     * 根据直接关联的员工查询人员组信息
     *
     * @param selectGroupPageRequestVO
     * @return
     */
    List<SysGroup> selectGroupListByCondition(@Param("obj") SelectGroupPageRequestVO selectGroupPageRequestVO);

    void updateByEmployeeIdGroupId(@Param("obj") SysEmployeeGroup sysEmployeeGroup);

    Integer updateByEmployeeIdGroupIdLastModified(@Param("obj") SysEmployeeGroup sysEmployeeGroup, @Param("lastModifyTime") LocalDateTime lastModifyTime);

    List<SysEmployeeGroup> selectEmployeeGroupListByGroupIds(@Param("ids") List<Long> groupIdList, @Param("isDeleted") String isDeleted);

    Integer updateByEmployeeId(@Param("obj") SysEmployeeGroup sysEmployeeGroup);
}
